package com.example.demo.string;

/**
 * 判断子序列
 * https://leetcode.cn/problems/is-subsequence/description/?envType=study-plan-v2&envId=top-interview-150
 */
public class IsSubsequence {

    public boolean isSubsequence(String s, String t) {
        int n1 = s.length();
        int n2 = t.length();

        int i = 0;
        int j = 0;

        while (i < n1 && j < n2) {
            if (s.charAt(i) == t.charAt(j)) {
                i++;
            }
            j++;
        }

        return i == n1;
    }
}
